package com.vincent.kdp.view;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebView;

import com.vincent.baseapp.util.CommonUtil;

/**
 * Created by fuxingxing on 17/2/15.
 */

public class LoadingWebChromeClient extends WebChromeClient {

    private Activity thisActivity;

    public LoadingWebChromeClient(Activity thisActivity) {
        super();
        this.thisActivity = thisActivity;
        CommonUtil.showLoadingView(thisActivity);
    }

    @Override
    public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
        AlertDialog.Builder b2 = new AlertDialog.Builder(thisActivity).setTitle("提示")
                .setMessage(message).setPositiveButton("确定", new AlertDialog.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        result.confirm();
                    }
                });
        b2.setCancelable(false);
        b2.create();
        b2.show();
        return true;
    }

    @Override
    public void onProgressChanged(WebView view, int newProgress) {
        super.onProgressChanged(view, newProgress);
        if(newProgress>=100){
            CommonUtil.dismissLoadingView(thisActivity);
        }
    }
}
